<?php

/**
 * This is the model class for table "gnuhealth_patient".
 *
 * The followings are the available columns in table 'gnuhealth_patient':
 * @property integer $id
 * @property string $create_date
 * @property string $write_date
 * @property integer $create_uid
 * @property integer $write_uid
 * @property integer $family
 * @property string $photo
 * @property string $sex
 * @property string $blood_type
 * @property string $general_info
 * @property integer $primary_care_doctor
 * @property string $critical_info
 * @property string $rh
 * @property integer $current_address
 * @property integer $ethnic_group
 * @property integer $name
 * @property string $dob
 * @property string $marital_status
 * @property string $dod
 * @property integer $current_insurance
 * @property integer $cod
 * @property string $identification_code
 * @property boolean $deceased
 * @property boolean $works_at_home
 * @property boolean $prison_current
 * @property integer $fam_apgar_score
 * @property boolean $domestic_violence
 * @property boolean $hostile_area
 * @property boolean $sexual_abuse
 * @property boolean $sewers
 * @property integer $hours_outside
 * @property string $ses
 * @property string $education
 * @property boolean $television
 * @property integer $occupation
 * @property boolean $drug_addiction
 * @property string $fam_apgar_timesharing
 * @property boolean $electricity
 * @property string $housing
 * @property boolean $school_withdrawal
 * @property string $income
 * @property boolean $single_parent
 * @property string $ses_notes
 * @property string $fam_apgar_affection
 * @property boolean $gas
 * @property boolean $internet
 * @property boolean $telephone
 * @property boolean $water
 * @property string $fam_apgar_discussion
 * @property boolean $working_children
 * @property string $fam_apgar_help
 * @property boolean $trash
 * @property boolean $teenage_pregnancy
 * @property boolean $prison_past
 * @property boolean $relative_in_prison
 * @property string $fam_apgar_decisions
 * @property integer $full_term
 * @property boolean $colposcopy
 * @property boolean $breast_self_examination
 * @property boolean $pap_test
 * @property boolean $mammography
 * @property integer $menopause
 * @property integer $stillbirths
 * @property string $pap_test_last
 * @property boolean $fertile
 * @property string $colposcopy_last
 * @property boolean $menopausal
 * @property string $mammography_last
 * @property integer $abortions
 * @property integer $premature
 * @property integer $menarche
 * @property integer $gravida
 * @property string $sexuality_info
 * @property integer $smoking_number
 * @property string $sexual_partners
 * @property boolean $soft_drinks
 * @property boolean $coffee
 * @property integer $exercise_minutes_day
 * @property string $sexual_practices
 * @property boolean $ex_drug_addict
 * @property string $sexual_preferences
 * @property boolean $car_child_safety
 * @property boolean $alcohol
 * @property boolean $ex_alcoholic
 * @property integer $age_start_drugs
 * @property integer $number_of_meals
 * @property integer $coffee_cups
 * @property boolean $exercise
 * @property boolean $sex_with_prostitutes
 * @property boolean $sleep_during_daytime
 * @property integer $age_quit_smoking
 * @property boolean $ex_smoker
 * @property string $lifestyle_info
 * @property boolean $car_seat_belt
 * @property string $diet_info
 * @property boolean $drug_iv
 * @property boolean $second_hand_smoker
 * @property integer $age_quit_drugs
 * @property integer $alcohol_liquor_number
 * @property boolean $eats_alone
 * @property integer $age_quit_drinking
 * @property string $sex_oral
 * @property boolean $home_safety
 * @property integer $age_start_drinking
 * @property integer $first_sexual_encounter
 * @property boolean $smoking
 * @property string $sex_anal
 * @property integer $age_start_smoking
 * @property integer $sexual_partners_number
 * @property boolean $car_revision
 * @property boolean $motorcycle_rider
 * @property boolean $helmet
 * @property integer $alcohol_beer_number
 * @property boolean $traffic_laws
 * @property integer $sleep_hours
 * @property integer $alcohol_wine_number
 * @property boolean $diet
 * @property string $anticonceptive
 * @property boolean $prostitute
 * @property boolean $salt
 * @property boolean $drug_usage
 *
 * The followings are the available model relations:
 * @property ResUser $createU
 * @property PartyAddress $currentAddress
 * @property GnuhealthEthnicity $ethnicGroup
 * @property GnuhealthFamily $family0
 * @property PartyParty $name0
 * @property GnuhealthOccupation $occupation0
 * @property GnuhealthPhysician $primaryCareDoctor
 * @property ResUser $writeU
 */
class GnuhealthPatient extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'gnuhealth_patient';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('sex, name', 'required'),
			array('create_uid, write_uid, family, primary_care_doctor, current_address, ethnic_group, name, current_insurance, cod, fam_apgar_score, hours_outside, occupation, full_term, menopause, stillbirths, abortions, premature, menarche, gravida, smoking_number, exercise_minutes_day, age_start_drugs, number_of_meals, coffee_cups, age_quit_smoking, age_quit_drugs, alcohol_liquor_number, age_quit_drinking, age_start_drinking, first_sexual_encounter, age_start_smoking, sexual_partners_number, alcohol_beer_number, sleep_hours, alcohol_wine_number', 'numerical', 'integerOnly'=>true),
			array('create_date, write_date', 'length', 'max'=>6),
			array('photo, blood_type, general_info, critical_info, rh, dob, marital_status, dod, identification_code, deceased, works_at_home, prison_current, domestic_violence, hostile_area, sexual_abuse, sewers, ses, education, television, drug_addiction, fam_apgar_timesharing, electricity, housing, school_withdrawal, income, single_parent, ses_notes, fam_apgar_affection, gas, internet, telephone, water, fam_apgar_discussion, working_children, fam_apgar_help, trash, teenage_pregnancy, prison_past, relative_in_prison, fam_apgar_decisions, colposcopy, breast_self_examination, pap_test, mammography, pap_test_last, fertile, colposcopy_last, menopausal, mammography_last, sexuality_info, sexual_partners, soft_drinks, coffee, sexual_practices, ex_drug_addict, sexual_preferences, car_child_safety, alcohol, ex_alcoholic, exercise, sex_with_prostitutes, sleep_during_daytime, ex_smoker, lifestyle_info, car_seat_belt, diet_info, drug_iv, second_hand_smoker, eats_alone, sex_oral, home_safety, smoking, sex_anal, car_revision, motorcycle_rider, helmet, traffic_laws, diet, anticonceptive, prostitute, salt, drug_usage', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, create_date, write_date, create_uid, write_uid, family, photo, sex, blood_type, general_info, primary_care_doctor, critical_info, rh, current_address, ethnic_group, name, dob, marital_status, dod, current_insurance, cod, identification_code, deceased, works_at_home, prison_current, fam_apgar_score, domestic_violence, hostile_area, sexual_abuse, sewers, hours_outside, ses, education, television, occupation, drug_addiction, fam_apgar_timesharing, electricity, housing, school_withdrawal, income, single_parent, ses_notes, fam_apgar_affection, gas, internet, telephone, water, fam_apgar_discussion, working_children, fam_apgar_help, trash, teenage_pregnancy, prison_past, relative_in_prison, fam_apgar_decisions, full_term, colposcopy, breast_self_examination, pap_test, mammography, menopause, stillbirths, pap_test_last, fertile, colposcopy_last, menopausal, mammography_last, abortions, premature, menarche, gravida, sexuality_info, smoking_number, sexual_partners, soft_drinks, coffee, exercise_minutes_day, sexual_practices, ex_drug_addict, sexual_preferences, car_child_safety, alcohol, ex_alcoholic, age_start_drugs, number_of_meals, coffee_cups, exercise, sex_with_prostitutes, sleep_during_daytime, age_quit_smoking, ex_smoker, lifestyle_info, car_seat_belt, diet_info, drug_iv, second_hand_smoker, age_quit_drugs, alcohol_liquor_number, eats_alone, age_quit_drinking, sex_oral, home_safety, age_start_drinking, first_sexual_encounter, smoking, sex_anal, age_start_smoking, sexual_partners_number, car_revision, motorcycle_rider, helmet, alcohol_beer_number, traffic_laws, sleep_hours, alcohol_wine_number, diet, anticonceptive, prostitute, salt, drug_usage', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'createU' => array(self::BELONGS_TO, 'ResUser', 'create_uid'),
			'currentAddress' => array(self::BELONGS_TO, 'PartyAddress', 'current_address'),
			'ethnicGroup' => array(self::BELONGS_TO, 'GnuhealthEthnicity', 'ethnic_group'),
			'family0' => array(self::BELONGS_TO, 'GnuhealthFamily', 'family'),
			'name0' => array(self::BELONGS_TO, 'PartyParty', 'name'),
			'occupation0' => array(self::BELONGS_TO, 'GnuhealthOccupation', 'occupation'),
			'primaryCareDoctor' => array(self::BELONGS_TO, 'GnuhealthPhysician', 'primary_care_doctor'),
			'writeU' => array(self::BELONGS_TO, 'ResUser', 'write_uid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'create_date' => 'Create Date',
			'write_date' => 'Write Date',
			'create_uid' => 'Create Uid',
			'write_uid' => 'Write Uid',
			'family' => 'Family',
			'photo' => 'Photo',
			'sex' => 'Sex',
			'blood_type' => 'Blood Type',
			'general_info' => 'General Info',
			'primary_care_doctor' => 'Primary Care Doctor',
			'critical_info' => 'Critical Info',
			'rh' => 'Rh',
			'current_address' => 'Current Address',
			'ethnic_group' => 'Ethnic Group',
			'name' => 'Name',
			'dob' => 'Dob',
			'marital_status' => 'Marital Status',
			'dod' => 'Dod',
			'current_insurance' => 'Current Insurance',
			'cod' => 'Cod',
			'identification_code' => 'Identification Code',
			'deceased' => 'Deceased',
			'works_at_home' => 'Works At Home',
			'prison_current' => 'Prison Current',
			'fam_apgar_score' => 'Fam Apgar Score',
			'domestic_violence' => 'Domestic Violence',
			'hostile_area' => 'Hostile Area',
			'sexual_abuse' => 'Sexual Abuse',
			'sewers' => 'Sewers',
			'hours_outside' => 'Hours Outside',
			'ses' => 'Ses',
			'education' => 'Education',
			'television' => 'Television',
			'occupation' => 'Occupation',
			'drug_addiction' => 'Drug Addiction',
			'fam_apgar_timesharing' => 'Fam Apgar Timesharing',
			'electricity' => 'Electricity',
			'housing' => 'Housing',
			'school_withdrawal' => 'School Withdrawal',
			'income' => 'Income',
			'single_parent' => 'Single Parent',
			'ses_notes' => 'Ses Notes',
			'fam_apgar_affection' => 'Fam Apgar Affection',
			'gas' => 'Gas',
			'internet' => 'Internet',
			'telephone' => 'Telephone',
			'water' => 'Water',
			'fam_apgar_discussion' => 'Fam Apgar Discussion',
			'working_children' => 'Working Children',
			'fam_apgar_help' => 'Fam Apgar Help',
			'trash' => 'Trash',
			'teenage_pregnancy' => 'Teenage Pregnancy',
			'prison_past' => 'Prison Past',
			'relative_in_prison' => 'Relative In Prison',
			'fam_apgar_decisions' => 'Fam Apgar Decisions',
			'full_term' => 'Full Term',
			'colposcopy' => 'Colposcopy',
			'breast_self_examination' => 'Breast Self Examination',
			'pap_test' => 'Pap Test',
			'mammography' => 'Mammography',
			'menopause' => 'Menopause',
			'stillbirths' => 'Stillbirths',
			'pap_test_last' => 'Pap Test Last',
			'fertile' => 'Fertile',
			'colposcopy_last' => 'Colposcopy Last',
			'menopausal' => 'Menopausal',
			'mammography_last' => 'Mammography Last',
			'abortions' => 'Abortions',
			'premature' => 'Premature',
			'menarche' => 'Menarche',
			'gravida' => 'Gravida',
			'sexuality_info' => 'Sexuality Info',
			'smoking_number' => 'Smoking Number',
			'sexual_partners' => 'Sexual Partners',
			'soft_drinks' => 'Soft Drinks',
			'coffee' => 'Coffee',
			'exercise_minutes_day' => 'Exercise Minutes Day',
			'sexual_practices' => 'Sexual Practices',
			'ex_drug_addict' => 'Ex Drug Addict',
			'sexual_preferences' => 'Sexual Preferences',
			'car_child_safety' => 'Car Child Safety',
			'alcohol' => 'Alcohol',
			'ex_alcoholic' => 'Ex Alcoholic',
			'age_start_drugs' => 'Age Start Drugs',
			'number_of_meals' => 'Number Of Meals',
			'coffee_cups' => 'Coffee Cups',
			'exercise' => 'Exercise',
			'sex_with_prostitutes' => 'Sex With Prostitutes',
			'sleep_during_daytime' => 'Sleep During Daytime',
			'age_quit_smoking' => 'Age Quit Smoking',
			'ex_smoker' => 'Ex Smoker',
			'lifestyle_info' => 'Lifestyle Info',
			'car_seat_belt' => 'Car Seat Belt',
			'diet_info' => 'Diet Info',
			'drug_iv' => 'Drug Iv',
			'second_hand_smoker' => 'Second Hand Smoker',
			'age_quit_drugs' => 'Age Quit Drugs',
			'alcohol_liquor_number' => 'Alcohol Liquor Number',
			'eats_alone' => 'Eats Alone',
			'age_quit_drinking' => 'Age Quit Drinking',
			'sex_oral' => 'Sex Oral',
			'home_safety' => 'Home Safety',
			'age_start_drinking' => 'Age Start Drinking',
			'first_sexual_encounter' => 'First Sexual Encounter',
			'smoking' => 'Smoking',
			'sex_anal' => 'Sex Anal',
			'age_start_smoking' => 'Age Start Smoking',
			'sexual_partners_number' => 'Sexual Partners Number',
			'car_revision' => 'Car Revision',
			'motorcycle_rider' => 'Motorcycle Rider',
			'helmet' => 'Helmet',
			'alcohol_beer_number' => 'Alcohol Beer Number',
			'traffic_laws' => 'Traffic Laws',
			'sleep_hours' => 'Sleep Hours',
			'alcohol_wine_number' => 'Alcohol Wine Number',
			'diet' => 'Diet',
			'anticonceptive' => 'Anticonceptive',
			'prostitute' => 'Prostitute',
			'salt' => 'Salt',
			'drug_usage' => 'Drug Usage',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('create_date',$this->create_date,true);
		$criteria->compare('write_date',$this->write_date,true);
		$criteria->compare('create_uid',$this->create_uid);
		$criteria->compare('write_uid',$this->write_uid);
		$criteria->compare('family',$this->family);
		$criteria->compare('photo',$this->photo,true);
		$criteria->compare('sex',$this->sex,true);
		$criteria->compare('blood_type',$this->blood_type,true);
		$criteria->compare('general_info',$this->general_info,true);
		$criteria->compare('primary_care_doctor',$this->primary_care_doctor);
		$criteria->compare('critical_info',$this->critical_info,true);
		$criteria->compare('rh',$this->rh,true);
		$criteria->compare('current_address',$this->current_address);
		$criteria->compare('ethnic_group',$this->ethnic_group);
		$criteria->compare('name',$this->name);
		$criteria->compare('dob',$this->dob,true);
		$criteria->compare('marital_status',$this->marital_status,true);
		$criteria->compare('dod',$this->dod,true);
		$criteria->compare('current_insurance',$this->current_insurance);
		$criteria->compare('cod',$this->cod);
		$criteria->compare('identification_code',$this->identification_code,true);
		$criteria->compare('deceased',$this->deceased);
		$criteria->compare('works_at_home',$this->works_at_home);
		$criteria->compare('prison_current',$this->prison_current);
		$criteria->compare('fam_apgar_score',$this->fam_apgar_score);
		$criteria->compare('domestic_violence',$this->domestic_violence);
		$criteria->compare('hostile_area',$this->hostile_area);
		$criteria->compare('sexual_abuse',$this->sexual_abuse);
		$criteria->compare('sewers',$this->sewers);
		$criteria->compare('hours_outside',$this->hours_outside);
		$criteria->compare('ses',$this->ses,true);
		$criteria->compare('education',$this->education,true);
		$criteria->compare('television',$this->television);
		$criteria->compare('occupation',$this->occupation);
		$criteria->compare('drug_addiction',$this->drug_addiction);
		$criteria->compare('fam_apgar_timesharing',$this->fam_apgar_timesharing,true);
		$criteria->compare('electricity',$this->electricity);
		$criteria->compare('housing',$this->housing,true);
		$criteria->compare('school_withdrawal',$this->school_withdrawal);
		$criteria->compare('income',$this->income,true);
		$criteria->compare('single_parent',$this->single_parent);
		$criteria->compare('ses_notes',$this->ses_notes,true);
		$criteria->compare('fam_apgar_affection',$this->fam_apgar_affection,true);
		$criteria->compare('gas',$this->gas);
		$criteria->compare('internet',$this->internet);
		$criteria->compare('telephone',$this->telephone);
		$criteria->compare('water',$this->water);
		$criteria->compare('fam_apgar_discussion',$this->fam_apgar_discussion,true);
		$criteria->compare('working_children',$this->working_children);
		$criteria->compare('fam_apgar_help',$this->fam_apgar_help,true);
		$criteria->compare('trash',$this->trash);
		$criteria->compare('teenage_pregnancy',$this->teenage_pregnancy);
		$criteria->compare('prison_past',$this->prison_past);
		$criteria->compare('relative_in_prison',$this->relative_in_prison);
		$criteria->compare('fam_apgar_decisions',$this->fam_apgar_decisions,true);
		$criteria->compare('full_term',$this->full_term);
		$criteria->compare('colposcopy',$this->colposcopy);
		$criteria->compare('breast_self_examination',$this->breast_self_examination);
		$criteria->compare('pap_test',$this->pap_test);
		$criteria->compare('mammography',$this->mammography);
		$criteria->compare('menopause',$this->menopause);
		$criteria->compare('stillbirths',$this->stillbirths);
		$criteria->compare('pap_test_last',$this->pap_test_last,true);
		$criteria->compare('fertile',$this->fertile);
		$criteria->compare('colposcopy_last',$this->colposcopy_last,true);
		$criteria->compare('menopausal',$this->menopausal);
		$criteria->compare('mammography_last',$this->mammography_last,true);
		$criteria->compare('abortions',$this->abortions);
		$criteria->compare('premature',$this->premature);
		$criteria->compare('menarche',$this->menarche);
		$criteria->compare('gravida',$this->gravida);
		$criteria->compare('sexuality_info',$this->sexuality_info,true);
		$criteria->compare('smoking_number',$this->smoking_number);
		$criteria->compare('sexual_partners',$this->sexual_partners,true);
		$criteria->compare('soft_drinks',$this->soft_drinks);
		$criteria->compare('coffee',$this->coffee);
		$criteria->compare('exercise_minutes_day',$this->exercise_minutes_day);
		$criteria->compare('sexual_practices',$this->sexual_practices,true);
		$criteria->compare('ex_drug_addict',$this->ex_drug_addict);
		$criteria->compare('sexual_preferences',$this->sexual_preferences,true);
		$criteria->compare('car_child_safety',$this->car_child_safety);
		$criteria->compare('alcohol',$this->alcohol);
		$criteria->compare('ex_alcoholic',$this->ex_alcoholic);
		$criteria->compare('age_start_drugs',$this->age_start_drugs);
		$criteria->compare('number_of_meals',$this->number_of_meals);
		$criteria->compare('coffee_cups',$this->coffee_cups);
		$criteria->compare('exercise',$this->exercise);
		$criteria->compare('sex_with_prostitutes',$this->sex_with_prostitutes);
		$criteria->compare('sleep_during_daytime',$this->sleep_during_daytime);
		$criteria->compare('age_quit_smoking',$this->age_quit_smoking);
		$criteria->compare('ex_smoker',$this->ex_smoker);
		$criteria->compare('lifestyle_info',$this->lifestyle_info,true);
		$criteria->compare('car_seat_belt',$this->car_seat_belt);
		$criteria->compare('diet_info',$this->diet_info,true);
		$criteria->compare('drug_iv',$this->drug_iv);
		$criteria->compare('second_hand_smoker',$this->second_hand_smoker);
		$criteria->compare('age_quit_drugs',$this->age_quit_drugs);
		$criteria->compare('alcohol_liquor_number',$this->alcohol_liquor_number);
		$criteria->compare('eats_alone',$this->eats_alone);
		$criteria->compare('age_quit_drinking',$this->age_quit_drinking);
		$criteria->compare('sex_oral',$this->sex_oral,true);
		$criteria->compare('home_safety',$this->home_safety);
		$criteria->compare('age_start_drinking',$this->age_start_drinking);
		$criteria->compare('first_sexual_encounter',$this->first_sexual_encounter);
		$criteria->compare('smoking',$this->smoking);
		$criteria->compare('sex_anal',$this->sex_anal,true);
		$criteria->compare('age_start_smoking',$this->age_start_smoking);
		$criteria->compare('sexual_partners_number',$this->sexual_partners_number);
		$criteria->compare('car_revision',$this->car_revision);
		$criteria->compare('motorcycle_rider',$this->motorcycle_rider);
		$criteria->compare('helmet',$this->helmet);
		$criteria->compare('alcohol_beer_number',$this->alcohol_beer_number);
		$criteria->compare('traffic_laws',$this->traffic_laws);
		$criteria->compare('sleep_hours',$this->sleep_hours);
		$criteria->compare('alcohol_wine_number',$this->alcohol_wine_number);
		$criteria->compare('diet',$this->diet);
		$criteria->compare('anticonceptive',$this->anticonceptive,true);
		$criteria->compare('prostitute',$this->prostitute);
		$criteria->compare('salt',$this->salt);
		$criteria->compare('drug_usage',$this->drug_usage);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return GnuhealthPatient the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
